package com.yuzhi.master.sewageTreatment.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.yuzhi.framework.handler.geometry.GeometryTypeHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.locationtech.jts.geom.Geometry;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Data
@TableName(value = "drain_sewage_treatment", schema = "psbiz")
public class SwageTreatmentEntity {

    @TableId(value = "id", type = IdType.ASSIGN_UUID)
    @Schema(description = "主键")
    private String id;

    @Schema(description = "代码")
    private String factId;

    @TableField("sys_id")
    @Schema(description = "排水系统代码")
    private String sysId;

    @TableField("fact_name")
    @NotBlank(message = "工厂名称不能为空")
    @Schema(description = "污水厂名称")
    private String factName;

    /**
     * 污水厂简称
     */
    @Schema(description = "污水厂简称")
    private String shortName;

    @TableField("fact_add")
    @Schema(description = "地址")
    private String factAdd;

    @TableField("fact_phone")
    @Schema(description = "联系电话")
    private String factPhone;

    @TableField("fact_post_code")
    @Schema(description = "邮政编码")
    private String factPostCode;

    @TableField("fact_grade")
    @Schema(description = "等级1-市管，2-区管，3-镇管，9-其它")
    private Integer factGrade;

    @TableField("fact_com_id")
    @Schema(description = "所属公司代码")
    private String factComId;

    @TableField("fact_cap_dsn")
    @NotNull(message = "设计处理能力不能为空")
    @Schema(description = "设计规模（万立方米/日）")
    private BigDecimal factCapDsn;

    @TableField("fact_cap_fact")
    @Schema(description = "处理水量（万立方米/日）")
    private BigDecimal factCapFact;

    @TableField("fact_method_treat")
    @Schema(description = "污水处理工艺")
    private String factMethodTreat;

    @TableField("fact_pow_unit")
    @Schema(description = "处理单耗（千瓦时/立方米）")
    private BigDecimal factPowUnit;

    @TableField("fact_pow_day")
    @Schema(description = "处理用电量（千瓦时/日）")
    private BigDecimal factPowDay;

    @TableField("fact_bod_in")
    @Schema(description = "BOD进水浓度（毫克每升）")
    private BigDecimal factBodIn;

    @TableField("fact_bod_out")
    @Schema(description = "BOD出水浓度（毫克每升）")
    private BigDecimal factBodOut;

    @TableField("fact_cod_in")
    @Schema(description = "COD进水浓度（毫克每升）")
    private BigDecimal factCodIn;

    @TableField("fact_cod_out")
    @Schema(description = "COD出水浓度（毫克每升）")
    private BigDecimal factCodOut;

    @TableField("fact_ss_in")
    @Schema(description = "SS进水浓度（毫克每升）")
    private BigDecimal factSsIn;

    @TableField("fact_ss_out")
    @Schema(description = "SS出水浓度（毫克每升）")
    private BigDecimal factSsOut;

    @TableField("fact_nh3n_in")
    @Schema(description = "NH3-N进水浓度（毫克每升）")
    private BigDecimal factNh3nIn;

    @TableField("fact_nh3n_out")
    @Schema(description = "NH3-N出水浓度（毫克每升）")
    private BigDecimal factNh3nOut;

    @TableField("fact_p_in")
    @Schema(description = "磷进水浓度（毫克每升）")
    private BigDecimal factPIn;

    @TableField("fact_p_out")
    @Schema(description = "磷出水浓度（毫克每升）")
    private BigDecimal factPOut;

    @TableField("fact_type_treat")
    @Schema(description = "污泥处理")
    private String factTypeTreat;

    @TableField("fact_towhere")
    @Schema(description = "污泥出路")
    private String factTowhere;

    @TableField("fact_sullage_y")
    @Schema(description = "污泥量（立方米/年）")
    private BigDecimal factSullageY;

    @TableField("fact_n_factor")
    @Schema(description = "污泥含水率（%）")
    private BigDecimal factNFactor;

    @TableField("fact_to_riv")
    @Schema(description = "排入水体名称")
    private String factToRiv;

    @TableField("fact_state")
    @Schema(description = "设施状态1-拟建、2-已建、3-已废")
    private Integer factState;

    @TableField("fact_area_use")
    @Schema(description = "占地面积（平方米）")
    private BigDecimal factAreaUse;

    @TableField("fact_area_s")
    @Schema(description = "服务面积（平方米）")
    private BigDecimal factAreaS;

    @TableField("fact_popu_s")
    @Schema(description = "服务人口数（万人）")
    private BigDecimal factPopuS;

    @TableField("fact_type_bld")
    @Schema(description = "建设规模：1-大型，2-中型，3-小型")
    private Integer factTypeBld;

    @TableField("fact_date_finish")
    @Schema(description = "竣工年月")
    private LocalDate factDateFinish;

    @TableField("fact_com_dsn")
    @Schema(description = "设计单位")
    private String factComDsn;

    @TableField("fact_com_build")
    @Schema(description = "施工单位")
    private String factComBuild;

    @TableField("fact_plan")
    @Schema(description = "平面图")
    private String factPlan;

    @TableField("fact_map")
    @Schema(description = "处理工艺图")
    private String factMap;

    @TableField("drai_pipe_id")
    @Schema(description = "外接管道代码")
    private String draiPipeId;

    @TableField("fact_remark")
    @Schema(description = "备注")
    private String factRemark;

    @TableField("area_code")
    @Schema(description = "行政区域(对应行政区域XXX表)")
    private String areaCode;

    @TableField("radiation_range")
    @Schema(description = "辐射范围(关联drain_radiation_range表，多条数据逗号隔开)")
    private String radiationRange;

    @TableField("dz_fact")
    @Schema(description = "污水厂分类(1：重点污水厂，2、其他厂)")
    private Integer dzFact;

    @TableField("longitude")
    @Schema(description = "经度")
    private BigDecimal longitude;

    @TableField("latitude")
    @Schema(description = "纬度")
    private BigDecimal latitude;

    @Schema(description = "关联图片id")
    private String ossId;

    /**
     * 是否有全景图(0:否  1:是)
     */
    private String hasPanorama;

    /**
     * 出水流量
     */
    @TableField(exist = false)
    private Double csLg;

    /**
     * 厂区的范围地理空间字段
     */
    @TableField(typeHandler = GeometryTypeHandler.class)
    @JsonIgnore // 避免 Geometry 对象直接参与 JSON 序列化
    private Geometry factAreaGeo;

    /**
     * 厂区的范围坐标
     */
    @TableField(exist = false)
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<List<Double>> coordinates = new ArrayList<>();

    // 确保安全的 getter 方法
    public List<List<Double>> getCoordinates() {
        if (this.coordinates == null) {
            this.coordinates = new ArrayList<>();
        }
        return this.coordinates;
    }

}
